<#include "/common/dialogbox.html">
<@header>
</@header>
<@body>
<div class="x_content">
	<form class="form-horizontal form-label-left"  role="form" method="post" action="${ctx}/system/menu/doEdit" id="menuEditActionForm">
		<input type="hidden" name="id" value="${(sysMenu.id)!}" />
		<div class="form-group">
			<label class="control-label col-md-2 col-sm-2 col-xs-12">
				父级目录 <span class="required">*</span>
			</label>
			<div class="col-md-9 col-sm-9 col-xs-12">
				<select id="dir" class="form-control select2" style="width: 100%;" required>
				  <option value="" selected="selected">--请选择--</option>
				  <#list list as m>
				  	 <option value="${(m.id)!}" ${(m.id==pSysMenu.pid)?string('selected="selected"','')}> ${(m.menuName)!}</option>
				  </#list>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-md-2 col-sm-2 col-xs-12">
				上级菜单 <span class="required">*</span>
			</label>
			<div class="col-md-9 col-sm-9 col-xs-12">
				<select id="pid" name="pid" class="form-control select2" style="width: 100%;" required>
					<option value="${(pSysMenu.id)!}" selected="selected"> ${(pSysMenu.menuName)!}</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-md-2 col-sm-2 col-xs-12">
				功能名称 <span class="required">*</span>
			</label>
			<div class="col-md-9 col-sm-9 col-xs-12">
	      		<input type="text" name="menuName" value="${(sysMenu.menuName)!}" class="form-control" placeholder="请输入目录名称" required>
      		</div>
		</div>
		<div class="form-group">
			<label class="control-label col-md-2 col-sm-2 col-xs-12">
				权限标识 <span class="required">*</span>
			</label>
			<div class="col-md-9 col-sm-9 col-xs-12">
	      		<input type="text" id="resource" name="resource" value="${(sysMenu.resource)!}" class="form-control" placeholder="请输入权限资源名称" required>
	      		<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 控制器中定义的权限标识，如：@RequiresPermissions("")</span>
      		</div>
		</div>
		<div class="form-group">
			<label class="control-label col-md-2 col-sm-2 col-xs-12">
				按钮排序 <span class="required">*</span>
			</label>
			<div class="col-md-9 col-sm-9 col-xs-12">
	      		<input type="text" name="sort" value="${(sysMenu.sort)!}" class="form-control" placeholder="请输入排序" required>
	      		<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 第三层级按钮顺序</span>
      		</div>
		</div>
	</form>
</div>
</@body>
<@footer>
<script type="text/javascript">
$("#dir").on('change',function(){
	var pid = $(this).val();
	 $.post('/system/menu/json?_dc='+new Date().getTime(),{pid:pid},function(response){
		if(response.code==200){
			$("#pid").empty();
			$("#pid").select2({
				data:response.data
			});
		}
	});
});

function submitHandler() {
	if ($("#menuEditActionForm").validate().form()) {
		var formData = $("#menuEditActionForm").serialize();
		$.ajax({
			url : $("#menuEditActionForm").attr('action'),
			type : 'POST',
			dataType: "json",
			data : formData,
			success : function(data) {
				if (data.code == 200) {
					if (data.msg) {
						parent.layer.msg(data.msg, {
							icon : 1
						});
					} else {
						parent.layer.msg('提交成功', {
							icon : 1
						});
					}
					window.parent.location.reload();
					parent.layer.closeAll('iframe');
				} else {
					layer.msg(data.msg, { icon : 2 });
				}
			}
		});
	}
}
</script>
</@footer>
